{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "tenserflow学习笔记.ipynb",
      "provenance": [],
      "collapsed_sections": [],
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/LIJIANcoder97/kaggle-ML/blob/master/tenserflow%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "UCjfnOzR92I6",
        "colab_type": "text"
      },
      "source": [
        "### 1, 加法"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "84H9FRyG8YSK",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "import tensorflow as tf"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "AobPcJS68oJp",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "a = tf.constant([1.0,2.0],name=\"a\")\n",
        "b = tf.constant([2.0,3.0],name=\"b\")"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "UuylEVdG87NQ",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "result = a+b"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "_35H3PyK9jUM",
        "colab_type": "code",
        "outputId": "b27057ac-8e92-4543-f01c-274b20cfa023",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "source": [
        "sess = tf.Session()\n",
        "sess.run(result)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([3., 5.], dtype=float32)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 6
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "4662bSKu-OJ0",
        "colab_type": "text"
      },
      "source": [
        "tf 结果不能直接输出，需建立会话输出结果"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "R-F81xYk-fSQ",
        "colab_type": "code",
        "outputId": "c5c4e203-7746-4cdf-f571-504e683b3a44",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "source": [
        "tf.get_default_graph"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "<function tensorflow.python.framework.ops.get_default_graph>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 8
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "0YH5lninGhcS",
        "colab_type": "text"
      },
      "source": [
        "前向传播算法，从输入变量开始向前计算，本质是矩阵传播"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "T28TrDanG2cH",
        "colab_type": "text"
      },
      "source": [
        "变量，计算前必须为变量初始化"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "sUxJcFukGgae",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "w1 = tf.Variable(tf.random_nomal((2,3),stadev=1,seed=1))\n",
        "sess=tf.Session()\n",
        "sess.run(w1.initializer)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "TJaJ-hY8HpRJ",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "#或\n",
        "init_op = tf.global_variables_initializer()\n",
        "sess.run(init_op)"
      ],
      "execution_count": 0,
      "outputs": []
    }
  ]
}